<?php
namespace app\frontend\controllers;

use app\models\Old;
use Phalcon\Paginator\Adapter\Model as Paginator;
use app\frontend\forms\BaseInsSearchForm;
/**
 * 仪器控制器
 * Class InsController
 */
class InsController extends ControllerBase
{

    public function initialize(){
        parent::initialize();
        $this->assets->addJs('pc/js/setwindow.js');
        $this->view->setTemplateBefore('information');
    }

    public function oldAction()
    {
        $this->tag->setTitle('折旧台账');
        $numberPage = 1;

        if ($this->request->isPost()) {
            $this->persistent->parameters = $this->request->hasPost('reset') ? []:$this->request->getPost();
        } else {
            $numberPage = $this->request->getQuery("page", "int");
        }

        $form = new BaseInsSearchForm();
        $this->persistent->parameters?$form->bind($this->persistent->parameters,$form):$form->clear();
        $query = $form->getQuery(Old::query());
        $inss = $query->execute();

        $paginator = new Paginator([
            'data' => $inss,
            'limit'=> 5,
            'page' => $numberPage
        ]);

        $this->view->setVars([
            'page'=>$paginator->getPaginate(),
            'form'=>$form,
        ]);
    }

    public function testAction()
    {
        $this->response->setHeader("Content-Type", "application/json");
        $inss= Old::find();
        $this->view->disable();
        echo json_encode($inss);
    }
}